	()		#pragma once
#include<iostream>
#include<list>
#include<assert.h>

using namespace std;

namespace Solution
{
	template<class T>
	class vector
	{
	public:

		typedef T* iterator;
		typedef const T* const_iterator;
		iterator begin(){return _start;}
		iterator end(){return _finish;}
		const_iterator begin()const{return _start;}
		const_iterator end()const{return _finish;}

		//vector() = default;

		template<class InputIterator>
		vector(InputIterator first, InputIterator last)
		{
			reserve(last - first);
			while (first!=last)
			{
				push_back(*first++);
			}
		}

		vector(const vector<T>& v)
		{
			reserve(v.size());
			for (auto cv : v)
			{
				push_back(cv);
			}
		}

		vector(int n = 0, const T& x = T())
		{
			while (n--)
				push_back(x);
		}

		vector<T>& operator=(vector<T> v)
		{
			swap(v);
			return *this;
		}
		
		~vector()
		{
			delete []_start;
			_finish = _start = _end_of_storage = nullptr;
		}

		const size_t size()const
		{
			return _finish - _start;
		}
		const size_t capacity()const
		{
			return _end_of_storage - _start;
		}

		const bool empty()const
		{
			return size()==0;
		}

		void clear()
		{
			_finish = _start;
		}

		const T& operator[](size_t pos)const
		{
			assert(pos < size());
			return _start[pos];
		}

		T& operator[](size_t pos)
		{
			assert(pos < size());
			return _start[pos];
		}


		void swap(const vector<T>& v)
		{
			std::swap(v._start,_start);
			std::swap(v._finish, _finish);
			std::swap(v._end_of_storage, _end_of_storage);
		}

		void reserve(size_t n)
		{
			if (n > capacity())
			{
				size_t old_size = size();
				T* tmp = new T[n];
				for (size_t i = 0; i < old_size; i++)
				{
					tmp[i] = _start[i];
				}
				delete[]_start;
				_start = tmp;
				_finish = _start + old_size;
				_end_of_storage = _start + n;
			}

		}
		void push_back(const T& x)
		{
			if (_finish == _end_of_storage)
			{
				reserve(capacity() == 0 ? 4 : 2 * capacity() * 2);
			}
			*_finish++ = x;
		}

		iterator insert(iterator pos, const T& x)
		{
			assert(pos >= _start && pos <= _end_of_storage);
			if (_finish == _end_of_storage)
			{
				size_t size = pos - _start;
				reserve(capacity() == 0 ? 4 : 2 * capacity());
				pos = _start + size;
			}
			iterator end = _finish++;
			while (end > pos)
			{
				*end = *(end - 1);
				end--;
			}
			*pos = x;
			return pos;
		}

		iterator erase(iterator pos)
		{
			assert(pos >= _start && pos <= _end_of_storage);
			iterator end = pos + 1;

			while (end<=_finish - 1)
			{
				_start[end - 1] = _start[end];
				end++;
			}
			_finish--;
			return pos;
		}

		void resize(size_t n, const T& val = T())
		{
			if (size() >= n)
				_finish = _start + n;
			else
			{
				reserve(n);
				iterator end = _finish;
				while (end<=_start + n)
				{
					*end++ = val;
				}
				_finish = _start + n;
			}
		}

		void pop_back()
		{
			assert(_start != _finish);
			_finish--;
		}


		

	private:
		iterator _start = nullptr;
		iterator _finish = nullptr;
		iterator _end_of_storage = nullptr;
	};

	template<class Container>
	void Print_Container(const Container& c)
	{	
		for (auto e : c)
		{
			cout << e << ' ';
		}
		cout << endl;
	}
	void test01()
	{
		vector<int>v;
		v.push_back(1);
		v.push_back(2);
		v.push_back(3);
		v.push_back(4);
		v.push_back(4);
		v.push_back(4);
		v.push_back(5);
		v.insert(v.begin() + 1, 100);
		v.insert(v.begin() + 1, 100);
		v.insert(v.begin() + 1, 100);
		v.insert(v.begin() + 1,100);
		v.resize(1);
		v.resize(13,10);
		vector<int>v1(12,9); 
		list<int> l(v1.begin(), v1.end());
		Print_Container(l);
		cout << endl;
	}
}